VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsRegistry"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit

Private Const REG_SZ = (1)
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const KEY_ALL_ACCESS = &H3F
Private Const ERROR_SUCCESS = 0&
Private Const REG_OPTION_NON_VOLATILE = 0&

Private mstrAsciiFileName As String
Private mstrErrorFileLocation As String

Public Property Let AsciiFileName(ByVal vData As String)
   'sets the system in the registry
    mstrAsciiFileName = vData
End Property
Public Property Get AsciiFileName() As String
    'gets the system from the registry
    AsciiFileName = mstrAsciiFileName
End Property

Public Property Let AdoConnectString(ByVal vData As String)
   'sets the system in the registry
    SaveSettingC "Software\Mindkey Software Solutions\KeyTax", "AdoConnectString", vData, REG_SZ
End Property
Public Property Get AdoConnectString() As String
    'gets the system from the registry
    AdoConnectString = GetSettingC("Software\Mindkey Software Solutions\KeyTax", "AdoConnectString")
End Property
Public Property Let AsciiFileDest(ByVal vData As String)
   'sets the system in the registry
   
   Dim intPos As Integer
   Dim strTemp As String
   
    SaveSettingC "Software\Mindkey Software Solutions\KeyTax", "AsciiFileDest", vData, REG_SZ
    mstrErrorFileLocation = vData & "Error\"
    
    
    
'    If Dir(mstrErrorFileLocation, vbDirectory) = "" Then
'        'MkDir mstrErrorFileLocation
'        intPos = InStr(1, mstrErrorFileLocation, "\")
'        strTemp = Left(mstrErrorFileLocation, intPos)
'        Do While intPos <> 0
'            If Dir(strTemp) = "" Then
'                MkDir strTemp
'            End If
'            intPos = InStr(intPos + 1, mstrErrorFileLocation, "\")
'            strTemp = Left(mstrErrorFileLocation, intPos)
'        Loop
'    End If
End Property
Public Property Get AsciiFileDest() As String
    'gets the system from the registry
    AsciiFileDest = GetSettingC("Software\Mindkey Software Solutions\KeyTax", "AsciiFileDest")
End Property

Public Property Get ErrorFileLocation() As String
    'gets the system from the registry
    ErrorFileLocation = mstrErrorFileLocation
End Property


'Public Property Let AsciiFileName(ByVal vData As String)
'   'sets the system in the registry
'    SaveSettingC "Software\Mindkey Software Solutions\KeyTax Extract", "AsciiFileName", vData, REG_SZ
'End Property
'Public Property Get AsciiFileName() As String
'    'gets the system from the registry
'    AsciiFileName = GetSettingC("Software\Mindkey Software Solutions\KeyTax Extract", "AsciiFileName")
'End Property

Private Sub SaveSettingC(strKeyName As String, strValueName As String, varValueSetting As Variant, lngValueType As Long)
'Purpose
'*******
'Set the value of a Registry key if it exists.
'if the registry key doesn't exist it will be created

On Error GoTo SaveSettingsCFix

'Variables
'*********
    Dim hKey As Long            'Handle to the key
    Dim lngRetVal As Long       'Result of API functions
    Dim SA As TSECURITY_ATTRIBUTES
    Dim create As Long

'Code
'****
    'Open or Ceate the registry key
    lngRetVal = RegCreateKeyEx(HKEY_LOCAL_MACHINE, strKeyName, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, SA, hKey, create)
    If lngRetVal <> ERROR_SUCCESS Then
        MsgBox "An error occured while trying to set the registry key", vbExclamation
        Exit Sub
    End If
    
    'Set or create a registry value
    lngRetVal = RegSetValueEx(hKey, strValueName, 0, lngValueType, varValueSetting, CLng(Len(varValueSetting) + 1))
        
    RegCloseKey (hKey)
    
    Exit Sub
    
SaveSettingsCFix:
    MsgBox "Options.SavesSettingsC: ", Err.Description
    
End Sub

'This function reads the registry
Private Function GetSettingC(strKeyName As String, strValueName As String) As String
'Purpose
'*******
'Gets the value a certain registry key

On Error GoTo GetSettingsIRP3bFix

'Variables
'*********
    Dim lngRetVal As Long           'Result of the API functions
    Dim hKey As Long                'Handle of the opened key
    Dim szBuffer As String          'Setting of the queried value
    Dim lngBuffSize As Long
    
'Code
'****
    'Create the buffer
    szBuffer = Space(255)
    lngBuffSize = 255
    
    'Open the specified registry key
    lngRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKeyName, 0, KEY_ALL_ACCESS, hKey)
    If lngRetVal <> ERROR_SUCCESS Then
        'MsgBox "Registry key or Value Name doesn't exist", vbExclamation
        Exit Function
    End If
    
    'Read the opened registry key
    lngRetVal = RegQueryValueEx(hKey, strValueName, 0, 0, szBuffer, lngBuffSize)
    
    GetSettingC = Trim(Left(szBuffer, lngBuffSize - 1))
    
    'Close the registry key
    RegCloseKey (hKey)

    Exit Function
    
GetSettingsIRP3bFix:
    MsgBox "clsOptions.GetSettingsC: " & Err.Description
    
End Function
